package com.hxzy.service.jobhandler;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.TimeUnit;

@Log4j2
@Component
public class PrintJobHandler {

    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("printHandler")
    public void demoJobHandler() throws Exception {
        log.info("定时任务调用并打印......");
    }

    /**
     * 2、简单任务示例（Bean模式）
     */
    @XxlJob("showHandler")
    public void showJobHandler() throws Exception {
        //接收参数，必须是json格式
        String param = XxlJobHelper.getJobParam();

        ObjectMapper  objectMapper=new ObjectMapper();
        Map map = objectMapper.readValue(param, Map.class);
        int n=Integer.parseInt(map.get("n").toString());

        for(int s=1;s<=n;s++) {
            log.info("定时任务调用并打印......"+s);
        }
    }

}
